package constant.milk.cashbook.data;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;

import jxl.Workbook;
import jxl.format.Alignment;
import jxl.format.Border;
import jxl.format.BorderLineStyle;
import jxl.format.Colour;
import jxl.format.ScriptStyle;
import jxl.format.UnderlineStyle;
import jxl.format.VerticalAlignment;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import constant.milk.cashbook.R;
import constant.milk.cashbook.SuperActivity;
import constant.milk.cashbook.asset.NameActivity;
import constant.milk.cashbook.bean.InOutData;
import constant.milk.cashbook.database.DBSelectQuery;
import constant.milk.cashbook.database.DbAdapter;
import constant.milk.cashbook.tip.TipInfoActivity;
import constant.milk.cashbook.tip.TipMap;
import constant.milk.cashbook.util.CalendarActivity;
import constant.milk.cashbook.util.MilkManager;
import constant.milk.cashbook.util.MilkUtil;

public class ExcelBankUpActivity extends SuperActivity
{
	public static final String EXCEL_FILE_NAME = "HouseCashBookEXCEL";
	
	public static final int DATE1_REQUEST_CODE = 0;
	public static final int DATE2_REQUEST_CODE = 1;
	public static final int NAME_REQUEST_CODE = 2;
	
	private TextView date1TextView;
	private TextView date2TextView;
	
	private View date1View;
	private View date2View;
	
	private View todayView;
	private View oneWeekView;
	private View oneMonthView;
	private View threeMonthView;
	private View halfYearView;
	private View oneYearView;
	
	private int year1;
	private int month1;
	private int day1;
	
	private int year2;
	private int month2;
	private int day2;
	
	private View nameView;
	private TextView nameTextView;
	
	private Button saveButton;
	
	private DBSelectQuery select;
	private MilkManager milkManager;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.excel_bankup_activity);
		
		setTitle("엑셀만들기");
		
		setFindViewId();
		setOnClick();
		setData();
	}

	@Override
	protected void setFindViewId()
	{
		date1TextView = (TextView) findViewById(R.id.excelBankUpDate1TextView);
		date2TextView = (TextView) findViewById(R.id.excelBankUpDate2TextView);
		
		date1View = findViewById(R.id.excelBankUpDate1View);
		date2View = findViewById(R.id.excelBankUpDate2View);
		
		todayView = findViewById(R.id.excelBankUpTodayView);
		oneWeekView = findViewById(R.id.excelBankUpOneWeekView);
		oneMonthView = findViewById(R.id.excelBankUpOneMonthView);
		threeMonthView = findViewById(R.id.excelBankUpThreeMonthView);
		halfYearView = findViewById(R.id.excelBankUpHalfYearView);
		oneYearView = findViewById(R.id.excelBankUpOneYearView);
		
		nameView = findViewById(R.id.excelBankUpNameView);
		nameTextView = (TextView) findViewById(R.id.excelBankUpNameTextView);
		
		saveButton = (Button) findViewById(R.id.saveButton);
	}

	@Override
	protected void setOnClick()
	{
		date1View.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent(superContext, CalendarActivity.class);
				intent.putExtra(CalendarActivity.YEAR, year1);
				intent.putExtra(CalendarActivity.MONTN, month1);
				intent.putExtra(CalendarActivity.DAY, day1);
				startActivityForResult(intent, DATE1_REQUEST_CODE);
			}
		});
		
		date2View.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent(superContext, CalendarActivity.class);
				intent.putExtra(CalendarActivity.YEAR, year2);
				intent.putExtra(CalendarActivity.MONTN, month2);
				intent.putExtra(CalendarActivity.DAY, day2);
				startActivityForResult(intent, DATE2_REQUEST_CODE);
			}
		});
		
		todayView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setToDate();
			}
		});
		
		oneWeekView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setOneWeekDate();
			}
		});
		
		oneMonthView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setOneMonthDate();
			}
		});
		
		threeMonthView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setThreeMonthDate();
			}
		});
		
		halfYearView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setHalfYearDate();
			}
		});
		
		oneYearView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setOneYearDate();
			}
		});
		
		nameView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent(superContext, NameActivity.class);
				intent.putExtra(NameActivity.NAME_DATA, nameTextView.getText().toString());
				startActivityForResult(intent, NAME_REQUEST_CODE);
			}
		});
		
		saveButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				if (setCheckData())
				{
					return;
				}
				
				if (setSaveData() == 0)
				{
					MilkUtil.showDialogFinish(superContext, "확인", "데이터 저장에 성공하였습니다.");
				}
				else if (setSaveData() == 1)
				{
					MilkUtil.showDialog(superContext, "실패", "컴퓨터에 연결을 빼고 해주세요.");
				}
				else if (setSaveData() == 3)
				{
					MilkUtil.showDialog(superContext, "실패", "기간내에 내역이 하나도 없습니다.");
				}
				else
				{
					MilkUtil.showDialog(superContext, "실패", "파일을 생성 할 수 없습니다. 개발자에게 메일을 보내주세요.");
				}
			}
		});
	}

	@Override
	protected void setData()
	{
		milkManager = new MilkManager(superContext, superDb);
		select = new DBSelectQuery(superContext, superDb);
		
		setToDate();
		
		String fileName = EXCEL_FILE_NAME;
		
		nameTextView.setText(fileName);
	}
	
	private void setToDate()
	{
		Calendar cal = Calendar.getInstance();
		
		year1 = cal.get(Calendar.YEAR);
		month1 = cal.get(Calendar.MONTH);
		day1 = cal.get(Calendar.DAY_OF_MONTH);
		
		year2 = cal.get(Calendar.YEAR);
		month2 = cal.get(Calendar.MONTH);
		day2 = cal.get(Calendar.DAY_OF_MONTH);
		
		setDate1();
		setDate2();
	}
	
	private void setOneWeekDate()
	{
		Calendar cal = Calendar.getInstance();
		Calendar cal2 = Calendar.getInstance();
		
		cal.add(Calendar.DAY_OF_MONTH, -6);
		year1 = cal.get(Calendar.YEAR);
		month1 = cal.get(Calendar.MONTH);
		day1 = cal.get(Calendar.DAY_OF_MONTH);
		
		year2 = cal2.get(Calendar.YEAR);
		month2 = cal2.get(Calendar.MONTH);
		day2 = cal2.get(Calendar.DAY_OF_MONTH);
		
		setDate1();
		setDate2();
	}
	
	private void setOneMonthDate()
	{
		Calendar cal = Calendar.getInstance();
		Calendar cal2 = Calendar.getInstance();
		
		cal.add(Calendar.MONTH, -1);
		cal.add(Calendar.DAY_OF_MONTH, 1);
		year1 = cal.get(Calendar.YEAR);
		month1 = cal.get(Calendar.MONTH);
		day1 = cal.get(Calendar.DAY_OF_MONTH);
		
		year2 = cal2.get(Calendar.YEAR);
		month2 = cal2.get(Calendar.MONTH);
		day2 = cal2.get(Calendar.DAY_OF_MONTH);
		
		setDate1();
		setDate2();
	}
	
	private void setThreeMonthDate()
	{
		Calendar cal = Calendar.getInstance();
		Calendar cal2 = Calendar.getInstance();
		
		cal.add(Calendar.MONTH, -3);
		cal.add(Calendar.DAY_OF_MONTH, 1);
		year1 = cal.get(Calendar.YEAR);
		month1 = cal.get(Calendar.MONTH);
		day1 = cal.get(Calendar.DAY_OF_MONTH);
		
		year2 = cal2.get(Calendar.YEAR);
		month2 = cal2.get(Calendar.MONTH);
		day2 = cal2.get(Calendar.DAY_OF_MONTH);
		
		setDate1();
		setDate2();
	}
	
	private void setHalfYearDate()
	{
		Calendar cal = Calendar.getInstance();
		Calendar cal2 = Calendar.getInstance();
		
		cal.add(Calendar.MONTH, -6);
		cal.add(Calendar.DAY_OF_MONTH, 1);
		year1 = cal.get(Calendar.YEAR);
		month1 = cal.get(Calendar.MONTH);
		day1 = cal.get(Calendar.DAY_OF_MONTH);
		
		year2 = cal2.get(Calendar.YEAR);
		month2 = cal2.get(Calendar.MONTH);
		day2 = cal2.get(Calendar.DAY_OF_MONTH);
		
		setDate1();
		setDate2();
	}
	
	private void setOneYearDate()
	{
		Calendar cal = Calendar.getInstance();
		Calendar cal2 = Calendar.getInstance();
		
		cal.add(Calendar.YEAR, -1);
		cal.add(Calendar.DAY_OF_MONTH, 1);
		year1 = cal.get(Calendar.YEAR);
		month1 = cal.get(Calendar.MONTH);
		day1 = cal.get(Calendar.DAY_OF_MONTH);
		
		year2 = cal2.get(Calendar.YEAR);
		month2 = cal2.get(Calendar.MONTH);
		day2 = cal2.get(Calendar.DAY_OF_MONTH);
		
		setDate1();
		setDate2();
	}
	
	private void setDate1()
	{
		date1TextView.setText(MilkUtil.getDate(year1, month1+1, day1));
	}
	
	private void setDate2()
	{
		date2TextView.setText(MilkUtil.getDate(year2, month2+1, day2));
	}
	
	private boolean setDateCheck(int date1, int date2)
	{
		if (date1 > date2)
		{
			MilkUtil.showToast(superContext, "앞에 날짜가 뒤에 날짜보다 클수 없습니다.");
			return false;
		}
		
		return true;
	}
	
	private int setSaveData()
	{
		WritableWorkbook workbook = null;
		
		try
		{
			ArrayList<InOutData> list = select.getInOutList(-1, "6", "", "", "", "",
					MilkUtil.getDateDB(year1, month1+1, day1), MilkUtil.getDateDB(year2, month2+1, day2));
			
			if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
			{
				return 1;
			}
			
			String fileName = nameTextView.getText().toString();
			
			File dir = new File(
					Environment.getExternalStorageDirectory() + "/"
							+ DataMainActivity.dirName);
			
			if (!dir.exists())
			{
				dir.mkdir();
			}
			
			File directory = new File(
					Environment.getExternalStorageDirectory() + "/" 
							+ DataMainActivity.dirNameExcel);
			
			if (!directory.exists())
			{
				directory.mkdir();
			}
			
			File file = new File(directory + "/" + fileName + ".xls");
			
			workbook = Workbook.createWorkbook(file); 
			
			// 기본 엑셀 서식 셋팅
			WritableCellFormat titleFormat = new WritableCellFormat(getExcelFont("title")); // 번호 셀 포멧 생성
		    WritableCellFormat dateFormat = new WritableCellFormat(getExcelFont("date")); // 이름 셀 포멧 생성
		    WritableCellFormat dataFormat = new WritableCellFormat(); // 데이터 셀 포멧 생성
		    WritableCellFormat outMoneyFormat = new WritableCellFormat(getExcelFont("out")); // 지출금액 셀 포멧 생성
		    WritableCellFormat inMoneyFormat = new WritableCellFormat(getExcelFont("in")); // 수입금액 셀 포멧 생성
		    WritableCellFormat moveMoneyFormat = new WritableCellFormat(getExcelFont("move")); // 이동금액 셀 포멧 생성
		    
		    titleFormat.setAlignment(Alignment.CENTRE); // 셀 가운데 정렬
		    titleFormat.setVerticalAlignment(VerticalAlignment.CENTRE); // 셀 수직 가운데 정렬
//		    titleFormat.setBorder(Border.ALL, BorderLineStyle.DASHED); // 보더와 보더라인스타일 설정
		    titleFormat.setBackground(Colour.ICE_BLUE); // 여름에 맞는 색깔 ? ^^
		  
		    dateFormat.setAlignment(Alignment.CENTRE); // 셀 가운데 정렬
		    dateFormat.setVerticalAlignment(VerticalAlignment.CENTRE); // 셀 수직 가운데 정렬
//		    dateFormat.setBorder(Border.ALL, BorderLineStyle.HAIR); // 보더와 보더라인스타일 설정
		    
		    dataFormat.setAlignment(Alignment.CENTRE); // 셀 가운데 정렬
		    dataFormat.setVerticalAlignment(VerticalAlignment.CENTRE); // 셀 수직 가운데 정렬
		    
		    outMoneyFormat.setAlignment(Alignment.RIGHT); // 셀 가운데 정렬
		    outMoneyFormat.setVerticalAlignment(VerticalAlignment.CENTRE); // 셀 수직 가운데 정렬
		    
		    inMoneyFormat.setAlignment(Alignment.RIGHT); // 셀 가운데 정렬
		    inMoneyFormat.setVerticalAlignment(VerticalAlignment.CENTRE); // 셀 수직 가운데 정렬
		    
		    moveMoneyFormat.setAlignment(Alignment.RIGHT); // 셀 가운데 정렬
		    moveMoneyFormat.setVerticalAlignment(VerticalAlignment.CENTRE); // 셀 수직 가운데 정렬
			
		    int labelCount = 1;
		    int cheetCount = 0;
			int date = Integer.MIN_VALUE;
			
			BigDecimal outMoney = BigDecimal.ZERO;
			BigDecimal inMoney = BigDecimal.ZERO;
			BigDecimal moveMoney = BigDecimal.ZERO;
			
			WritableSheet sheet = null;
			
			if (list.size() < 1)
			{
				return 3;
			}
			
			for (int i = 0; i < list.size(); i++)
			{
				InOutData data = list.get(i);
				
				int [] dates = MilkUtil.getDateSet(data.getDate());
				
				int dataDate = Integer.parseInt(MilkUtil.getDateDB2(dates[0], dates[1]));
				
				if (dataDate > date)
				{
					if (i > 0)
					{
						Label dataLabel1 = new Label(7, labelCount+1, "총지출", titleFormat);
						sheet.addCell(dataLabel1);
						Label dataLabel2 = new Label(8, labelCount+1, 
								MilkUtil.getWon(outMoney.toString()), outMoneyFormat);
					    sheet.addCell(dataLabel2);
					    
					    Label dataLabel3 = new Label(7, labelCount+2, "총수입", titleFormat);
						sheet.addCell(dataLabel3);
						Label dataLabel4 = new Label(8, labelCount+2, 
								MilkUtil.getWon(inMoney.toString()), inMoneyFormat);
					    sheet.addCell(dataLabel4);
					    
					    Label dataLabel5 = new Label(7, labelCount+3, "총이동", titleFormat);
						sheet.addCell(dataLabel5);
						Label dataLabel6 = new Label(8, labelCount+3, 
								MilkUtil.getWon(moveMoney.toString()), moveMoneyFormat);
					    sheet.addCell(dataLabel6);
					    
					    outMoney = BigDecimal.ZERO;
					    inMoney = BigDecimal.ZERO;
					    moveMoney = BigDecimal.ZERO;
					}
					
					date = dataDate;
					
					sheet = workbook.createSheet(dates[0] + "년 " + dates[1] + "월", cheetCount);
					
					sheet.setColumnView(0, 20);
					sheet.setColumnView(1, 15);
					sheet.setColumnView(2, 15);
					sheet.setColumnView(3, 15);
					sheet.setColumnView(4, 15);
					sheet.setColumnView(5, 20);
					sheet.setColumnView(6, 20);
					sheet.setColumnView(7, 20);
					sheet.setColumnView(8, 40);
					
					// 기본 표 셋팅
				    Label numberLabel1 = new Label(0, 0, "날짜", titleFormat);
				    sheet.addCell(numberLabel1); 
				    Label numberLabel2 = new Label(1, 0, "타입", titleFormat);
				    sheet.addCell(numberLabel2); 
				    Label numberLabel3 = new Label(2, 0, "자산", titleFormat);
				    sheet.addCell(numberLabel3); 
				    Label numberLabel4 = new Label(3, 0, "이름", titleFormat);
				    sheet.addCell(numberLabel4); 
				    Label numberLabel5 = new Label(4, 0, "설명", titleFormat);
				    sheet.addCell(numberLabel5); 
				    Label numberLabel6 = new Label(5, 0, "메인카테고리", titleFormat);
				    sheet.addCell(numberLabel6); 
				    Label numberLabel7 = new Label(6, 0, "서브카테고리", titleFormat);
				    sheet.addCell(numberLabel7); 
				    Label numberLabel8 = new Label(7, 0, "금액", titleFormat);
				    sheet.addCell(numberLabel8); 
				    Label numberLabel9 = new Label(8, 0, "내용", titleFormat);
				    sheet.addCell(numberLabel9); 
				    
				    labelCount = 1;
				    cheetCount = cheetCount + 1;
				}
			    
			    Label dataLabel1 = new Label(0, labelCount, MilkUtil.getDateButton(data.getDate()), dateFormat);
			    sheet.addCell(dataLabel1); 
			    Label dataLabel2 = new Label(1, labelCount, milkManager.getExcelType(data.getType()), dataFormat);
			    sheet.addCell(dataLabel2); 
			    Label dataLabel3 = new Label(2, labelCount, milkManager.getAssetId(data.getAsset()), dataFormat);
			    sheet.addCell(dataLabel3); 
			    Label dataLabel4 = new Label(3, labelCount, data.getName(), dataFormat);
			    sheet.addCell(dataLabel4); 
			    Label dataLabel5 = new Label(4, labelCount, milkManager.getExcelKind(data.getKind(), data.getType()), dataFormat);
			    sheet.addCell(dataLabel5); 
			    Label dataLabel6 = new Label(5, labelCount, data.getMaincategory(), dataFormat);
			    sheet.addCell(dataLabel6); 
			    Label dataLabel7 = new Label(6, labelCount, data.getSubcategory(), dataFormat);
			    sheet.addCell(dataLabel7); 
			    
			    if (milkManager.getExcelType(data.getType()).equals("지출"))
				{
			    	Label dataLabel8 = new Label(7, labelCount, MilkUtil.getWon(data.getMoney()), outMoneyFormat);
				    sheet.addCell(dataLabel8);
				    
				    outMoney = outMoney.add(new BigDecimal(MilkUtil.getCommaDel(data.getMoney())));
				}
			    else if (milkManager.getExcelType(data.getType()).equals("수입"))
				{
			    	Label dataLabel8 = new Label(7, labelCount, MilkUtil.getWon(data.getMoney()), inMoneyFormat);
				    sheet.addCell(dataLabel8);
				    
				    inMoney = inMoney.add(new BigDecimal(MilkUtil.getCommaDel(data.getMoney())));
				}
			    else if (milkManager.getExcelType(data.getType()).equals("이동"))
			    {
			    	Label dataLabel8 = new Label(7, labelCount, MilkUtil.getWon(data.getMoney()), moveMoneyFormat);
				    sheet.addCell(dataLabel8);
				    
				    moveMoney = moveMoney.add(new BigDecimal(MilkUtil.getCommaDel(data.getMoney())));
			    }
			    else
			    {
			    	Label dataLabel8 = new Label(7, labelCount, MilkUtil.getWon(data.getMoney()), dataFormat);
				    sheet.addCell(dataLabel8);
			    }
			    
			    Label dataLabel9 = new Label(8, labelCount, data.getMemo(), dataFormat);
			    sheet.addCell(dataLabel9);
			    
			    
			    labelCount = labelCount + 1;
			}
			
			Label dataLabel1 = new Label(7, labelCount+1, "총지출", titleFormat);
			sheet.addCell(dataLabel1);
			Label dataLabel2 = new Label(8, labelCount+1, 
					MilkUtil.getWon(outMoney.toString()), outMoneyFormat);
		    sheet.addCell(dataLabel2);
		    
		    Label dataLabel3 = new Label(7, labelCount+2, "총수입", titleFormat);
			sheet.addCell(dataLabel3);
			Label dataLabel4 = new Label(8, labelCount+2, 
					MilkUtil.getWon(inMoney.toString()), inMoneyFormat);
		    sheet.addCell(dataLabel4);
		    
		    Label dataLabel5 = new Label(7, labelCount+3, "총이동", titleFormat);
			sheet.addCell(dataLabel5);
			Label dataLabel6 = new Label(8, labelCount+3, 
					MilkUtil.getWon(moveMoney.toString()), moveMoneyFormat);
		    sheet.addCell(dataLabel6);
		    
		    outMoney = BigDecimal.ZERO;
		    inMoney = BigDecimal.ZERO;
		    moveMoney = BigDecimal.ZERO;
			
			workbook.write(); // 준비된 정보를 엑셀 포멧에 맞게 작성
		} catch (Exception e)
		{
			e.printStackTrace();
			return 2;
		} finally {
			try
			{
				if (workbook != null)
				{
					workbook.close();
				}
			} catch (Exception e)
			{
				e.printStackTrace();
				return 2;
			}
		}
		
		return 0;
	}
	
	/**
	 * 테이터가 제대로 있는지 확인한다.
	 */
	private boolean setCheckData()
	{
		String name = nameTextView.getText().toString();
		
		if (name.equals("") || name.length() < 1)
		{
			MilkUtil.showDialog(superContext, "확인", "이름을 입력해주세요.");
			return true;
		}
		
		return false;
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data)
	{
		super.onActivityResult(requestCode, resultCode, data);
		
		if (resultCode != Activity.RESULT_OK)
		{
			return;
		}
		
		if (requestCode == DATE1_REQUEST_CODE)
		{
			Calendar cal = Calendar.getInstance();
			int tyear1 = data.getIntExtra(CalendarActivity.YEAR, cal.get(Calendar.YEAR));
			int tmonth1 = data.getIntExtra(CalendarActivity.MONTN, cal.get(Calendar.MONTH));
			int tday1 = data.getIntExtra(CalendarActivity.DAY, cal.get(Calendar.DAY_OF_MONTH));
			
			int date1 = Integer.parseInt(MilkUtil.getDateDB(tyear1, tmonth1, tday1));
			int date2 = Integer.parseInt(MilkUtil.getDateDB(year2, month2, day2));
			
			if (!setDateCheck(date1, date2))
			{
				return;
			}
			
			year1 = data.getIntExtra(CalendarActivity.YEAR, cal.get(Calendar.YEAR));
			month1 = data.getIntExtra(CalendarActivity.MONTN, cal.get(Calendar.MONTH));
			day1 = data.getIntExtra(CalendarActivity.DAY, cal.get(Calendar.DAY_OF_MONTH));
			
			setDate1();
		}
		else if (requestCode == DATE2_REQUEST_CODE)
		{
			Calendar cal = Calendar.getInstance();
			int tyear2 = data.getIntExtra(CalendarActivity.YEAR, cal.get(Calendar.YEAR));
			int tmonth2 = data.getIntExtra(CalendarActivity.MONTN, cal.get(Calendar.MONTH));
			int tday2 = data.getIntExtra(CalendarActivity.DAY, cal.get(Calendar.DAY_OF_MONTH));
			
			int date1 = Integer.parseInt(MilkUtil.getDateDB(year1, month1, day1));
			int date2 = Integer.parseInt(MilkUtil.getDateDB(tyear2, tmonth2, tday2));
			
			if (!setDateCheck(date1, date2))
			{
				return;
			}
			
			year2 = data.getIntExtra(CalendarActivity.YEAR, cal.get(Calendar.YEAR));
			month2 = data.getIntExtra(CalendarActivity.MONTN, cal.get(Calendar.MONTH));
			day2 = data.getIntExtra(CalendarActivity.DAY, cal.get(Calendar.DAY_OF_MONTH));
			
			setDate2();
		}
		else if (requestCode == NAME_REQUEST_CODE)
		{
			String str = data.getStringExtra(NameActivity.NAME_DATA);
			nameTextView.setText(str);
		}
	}
	
	private WritableCellFormat getExcelFont(String fontName)
	{
		WritableCellFormat font = null;
		
		if (fontName.equals("title"))
		{
			font = new WritableCellFormat(new WritableFont(
				 	 WritableFont.ARIAL,          //폰트 타입.Arial 외 별다른건 없는듯 하다.
				 	 10,                          //폰트 크기 
				 	 WritableFont.BOLD,           //Bold 스타일
				 	 false,                       //이탤릭체여부
				 	 UnderlineStyle.NO_UNDERLINE, //밑줄 스타일
				 	 Colour.BLACK,                //폰트 색
				 	 ScriptStyle.NORMAL_SCRIPT)); //스크립트 스타일
		}
		else if (fontName.equals("date"))
		{
			font = new WritableCellFormat(new WritableFont(
					WritableFont.ARIAL,          //폰트 타입.Arial 외 별다른건 없는듯 하다.
					10,                          //폰트 크기 
					WritableFont.BOLD,           //Bold 스타일
					false,                       //이탤릭체여부
					UnderlineStyle.NO_UNDERLINE, //밑줄 스타일
					Colour.BLACK,                //폰트 색
					ScriptStyle.NORMAL_SCRIPT)); //스크립트 스타일
		}
		else if (fontName.equals("out"))
		{
			font = new WritableCellFormat(new WritableFont(
				 	 WritableFont.ARIAL,          //폰트 타입.Arial 외 별다른건 없는듯 하다.
				 	 10,                          //폰트 크기 
				 	 WritableFont.NO_BOLD,           //Bold 스타일
				 	 false,                       //이탤릭체여부
				 	 UnderlineStyle.NO_UNDERLINE, //밑줄 스타일
				 	 Colour.RED,                //폰트 색
				 	 ScriptStyle.NORMAL_SCRIPT)); //스크립트 스타일
		}
		else if (fontName.equals("in"))
		{
			font = new WritableCellFormat(new WritableFont(
				 	 WritableFont.ARIAL,          //폰트 타입.Arial 외 별다른건 없는듯 하다.
				 	 10,                          //폰트 크기 
				 	 WritableFont.NO_BOLD,           //Bold 스타일
				 	 false,                       //이탤릭체여부
				 	 UnderlineStyle.NO_UNDERLINE, //밑줄 스타일
				 	 Colour.BLUE,                //폰트 색
				 	 ScriptStyle.NORMAL_SCRIPT)); //스크립트 스타일
		}
		else if (fontName.equals("move"))
		{
			font = new WritableCellFormat(new WritableFont(
				 	 WritableFont.ARIAL,          //폰트 타입.Arial 외 별다른건 없는듯 하다.
				 	 10,                          //폰트 크기 
				 	 WritableFont.NO_BOLD,           //Bold 스타일
				 	 false,                       //이탤릭체여부
				 	 UnderlineStyle.NO_UNDERLINE, //밑줄 스타일
				 	 Colour.BROWN,                //폰트 색
				 	 ScriptStyle.NORMAL_SCRIPT)); //스크립트 스타일
		}
		
		return font;
	}

	@Override
	protected void tipButton()
	{
		Intent intent = new Intent(superContext, TipInfoActivity.class);
		intent.putExtra(TipInfoActivity.TIP_ID, TipMap.TIP_DATA_EXCEL);
		startActivity(intent);
	}

}
